package cn.geckos.util
{
	import flash.utils.ByteArray;
	import flash.utils.getQualifiedClassName;
	import flash.utils.getDefinitionByName;
	import flash.net.registerClassAlias;
	
	public class LangUtil
	{
		public function LangUtil(s:$singlon)
		{
			throw new Error("can not new this class");
		}
		
		public static function registerClassObjectAlias(source:Object):void
		{
			var typeName:String = getQualifiedClassName(source);//获取全名
        	var packageName:String = typeName.split("::")[1];//切出包名
        	var type:Class = Class(getDefinitionByName(typeName));//获取Class
			
			if(packageName == null)
			{
				packageName = type as String;
			}
        	registerClassAlias(packageName, type);//注册Class
		}
		
		/**
		 * 	Using this method to clone a new object, it's deep clone.
		 *  reference to: http://www.flashseer.org/bbs/viewthread.php?tid=217
		 * 	@author:胡矿
		*/
		public static function clone(source:Object):* {
 			
        	LangUtil.registerClassObjectAlias(source);
        	 
        	//复制对象
       	 	var copier:ByteArray = new ByteArray();
       	 	copier.writeObject(source);
        	copier.position = 0;
        	return copier.readObject();
		}
	}
}

class $singlon
{}